@extends('layouts.admin')

@section('title', '教师管理-编辑')
@section('style')
    <style>
        table tr td:nth-child(odd){width:15%;}
        table tr td:nth-child(even){width:18%;}
    </style>
@endsection

@section('content')
    <div id="tab_teacher" class="HuiTab">
        <div class="tabBar clearfix"><span>基本资料</span><span>上传头像</span><span>修改密码</span></div>
        <div class="tabCon">
            <article class="page-container">
                <form action="{{url('teacher/teacher/info_edit')}}" method="post" class="form form-horizontal" id="form-info-edit">
                    <input type="hidden" name="id" value="{{$editEntity->entity_id}}">
                    <table class="table table-border table-bordered">
                        <tr>
                            <td class="text-c">姓名</td>
                            <td><input type="text" value="{{$editEntity->name}}" name="name" id="name" class="input-text size-S" readonly></td>
                            <td class="text-c">电话</td>
                            <td><input type="text" value="{{$editEntity->phone}}" name="phone" id="phone" class="input-text size-S" readonly></td>
                            <td class="text-c">性别</td>
                            <td><select name="sex" id="sex" class="input-text size-S" disabled>
                                    <option value="M">男</option>
                                    <option value="F">女</option>
                                </select></td>
                        </tr>

                        <tr>
                            <td class="text-c">曾用名</td>
                            <td><input type="text" name="old_name" id="old_name"  value="{{$editEntity->old_name}}"  class="input-text size-S"></td>
                            <td class="text-c">身份证</td>
                            <td><input type="text" name="id_card" id="id_card" value="{{$editEntity->id_card}}" class="input-text size-S"></td>
                            <td class="text-c">民族</td>
                            <td><input type="text" name="nation" id="nation" value="{{$editEntity->nation}}" class="input-text size-S"></td>
                        </tr>
                        <tr>
                            <td class="text-c">出生日期</td>
                            <td>
                                <input type="text" onfocus="WdatePicker()" value="{{$editEntity->birth_date}}" id="birth_date" name="birth_date" class="input-text size-S Wdate">
                            </td>
                            <td class="text-c">工作时间</td>
                            <td>
                                <input type="text" onfocus="WdatePicker()" value="{{$editEntity->start_work_date}}" id="start_work_date" name="start_work_date" class="input-text size-S Wdate">
                            </td>
                            <td class="text-c">籍贯</td>
                            <td><input type="text"  id="hometown" name="hometown" value="{{$editEntity->hometown}}" class="input-text size-S"></td>
                        </tr>
                        <tr>
                            <td class="text-c">毕业时间</td>
                            <td>
                                <input type="text" onfocus="WdatePicker()" value="{{$editEntity->graduate_date}}" id="graduate_date" name="graduate_date" class="input-text size-S Wdate">
                            </td>
                            <td class="text-c">毕业学校</td>
                            <td>
                                <input type="text" value="{{$editEntity->graduate_school}}" name="graduate_school" id="graduate_school"  class="input-text size-S">
                            </td>
                            <td class="text-c">专业</td>
                            <td>
                                <input type="text" value="{{$editEntity->graduate_major}}" name="graduate_major" id="graduate_major"  class="input-text size-S">
                            </td>
                        </tr>
                        <tr>
                            <td class="text-c">学制</td>
                            <td>
                                <select name="graduate_school_system" id="graduate_school_system" class="input-text size-S">
                                    <option value="FOUR_YEAR">四年制</option>
                                    <option value="TREE_YEAR">三年制</option>
                                    <option value="OTHER">其他</option>
                                </select>
                            </td>
                            <td class="text-c">学位</td>
                            <td>
                                <input type="text" value="{{$editEntity->graduate_degree}}" name="graduate_degree" id="graduate_degree"  class="input-text size-S">
                            </td>
                            <td class="text-c">任职资格获取时间</td>
                            <td>
                                <input type="text" value="{{$editEntity->acquire_office_date}}" onfocus="WdatePicker()" id="acquire_office_date" name="acquire_office_date" class="input-text size-S Wdate">
                            </td>
                        </tr>
                        <tr>
                            <td class="text-c">政治面貌</td>
                            <td>
                                <input type="text" value="{{$editEntity->politics_status}}" name="politics_status" id="politics_status"  class="input-text size-S">
                            </td>
                            <td class="text-c">入党/团时间</td>
                            <td>
                                <input type="text" value="{{$editEntity->join_politics_org_date}}" onfocus="WdatePicker()" id="join_politics_org_date" name="join_politics_org_date" class="input-text size-S Wdate">
                            </td>
                            <td class="text-c">家庭联系人</td>
                            <td>
                                <input type="text" value="{{$editEntity->family_connect_user_name}}" name="family_connect_user_name" id="family_connect_user_name"  class="input-text size-S">
                            </td>
                        </tr>
                        <tr>
                            <td class="text-c">联系人关系</td>
                            <td>
                                <input type="text" value="{{$editEntity->family_connect_user_relation}}" name="family_connect_user_relation" id="family_connect_user_relation"  class="input-text size-S">
                            </td>
                            <td class="text-c">联系人电话</td>
                            <td>
                                <input type="text" value="{{$editEntity->family_connect_user_mobile}}" name="family_connect_user_mobile" id="family_connect_user_mobile"  class="input-text size-S">
                            </td>
                            <td class="text-c">联系人公司</td>
                            <td>
                                <input type="text" value="{{$editEntity->family_connect_user_company}}" name="family_connect_user_company" id="family_connect_user_company"  class="input-text size-S">
                            </td>
                        </tr>
                        <tr>
                            <td class="text-c">联系人职位</td>
                            <td>
                                <input type="text" value="{{$editEntity->family_connect_user_job}}" name="family_connect_user_job" id="family_connect_user_job"  class="input-text size-S">
                            </td>
                            <td class="text-c">联系人地址</td>
                            <td colspan="3">
                                <input type="text" value="{{$editEntity->family_connect_address}}" name="family_connect_address" id="family_connect_address"  class="input-text size-S">
                            </td>
                        </tr>
                    </table>
                    <p class="mt-10">
                        <input class="btn btn-primary radius info_edit_btn" type="submit" value="确认修改">
                        <input class="btn btn-secondary-outline radius info_cancel_btn" type="reset" value="取消修改">
                    </p>
                </form>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <form action="{{url('teacher/teacher/photo_edit')}}" method="post" class="form form-horizontal" id="form-photo-edit" enctype="multipart/form-data">
                    <input type="hidden" name="id"  value="{{$editEntity->entity_id}}">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>当前头像：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <img class="radius" width="100px" id="avatar" src="{{\App\Libs\Tools\UploadTools::getFileUrl($editEntity->photo)}}">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>上传头像：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input class="input-text upload-url" type="text" name="uploadfile-2" id="uploadfile-2" readonly>
                            <a href="javascript:void(0);" class="btn btn-primary upload-btn"><i class="Hui-iconfont">&#xe642;</i> 选择图片</a>
                            <input type="file"  name="photo" id="photo" class="input-file" style="height: 100%;">
                            </span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3"></label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input class="btn btn-primary radius photo_edit_btn" type="submit" value="确认修改">
                            <input class="btn btn-secondary-outline radius photo_cancel_btn" type="reset" value="取消修改">
                        </div>
                    </div>
                </form>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <form action="{{url('system/user/password_edit')}}" method="post" class="form form-horizontal" id="form-password-edit">
                    <input type="hidden" name="id"  value="{{$editEntity->entity_id}}">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>原密码：</label>
                        <div class="formControls col-xs-8 col-sm-10">
                            <input type="password" class="input-text" value="" placeholder="" id="old_password" name="old_password">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>新密码：</label>
                        <div class="formControls col-xs-8 col-sm-10">
                            <input type="password" class="input-text" value="" placeholder="" id="password" name="password">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>确认密码：</label>
                        <div class="formControls col-xs-8 col-sm-10">
                            <input type="password" class="input-text" value="" placeholder="" id="password_confirmation" name="password_confirmation">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"></label>
                        <div class="formControls col-xs-8 col-sm-10">
                            <input class="btn btn-primary radius password_edit_btn" type="submit" value="确认修改">
                            <input class="btn btn-secondary-outline radius password_cancel_btn" type="reset" value="取消修改">
                        </div>
                    </div>
                </form>
            </article>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function(){$("#tab_teacher").Huitab();})
        $("#sex").val('{{$editEntity->sex}}');
        $("#graduate_school_system").val('{{$editEntity->graduate_school_system}}');
        $("#form-info-edit").validate({
            rules:{
                acquire_office_date:{
                    required:true
                },
                old_name:{
                    required:true
                },
                id_card:{
                    required:true
                },
                nation:{
                    required:true
                },
                start_work_date:{
                    required:true
                },
                hometown:{
                    required:true
                },
                graduate_date:{
                    required:true
                },
                graduate_school:{
                    required:true
                },
                graduate_major:{
                    required:true
                },
                graduate_degree:{
                    required:true
                },
                join_politics_org_date:{
                    required:true
                },
                family_connect_user_name:{
                    required:true
                },
                family_connect_user_relation:{
                    required:true
                },
                family_connect_user_mobile:{
                    required:true
                },
                family_connect_user_company:{
                    required:true
                },
                family_connect_user_job:{
                    required:true
                },
                family_connect_address:{
                    required:true
                },
                birth_date:{
                    required:true
                },
                politics_status:{
                    required:true
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('teacher/teacher/info_edit')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("修改信息成功!");
                            setTimeout(function(){
                                window.location.reload();
                            },200);
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('修改信息失败!');
                    }
                });
            }
        });
    </script>
    <script>
        $("#form-photo-edit").validate({
            rules:{
                photo:{
                    required:true
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('teacher/teacher/photo_edit')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("修改头像成功!");
                            $('#avatar').attr('src',data.msg.url);
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('修改头像失败!');
                    }
                });
            }
        });
    </script>
    <script>
        $('#old_password').HuitogglePassword();
        $('#password').HuitogglePassword();
        $('#password_confirmation').HuitogglePassword();
        $("#form-password-edit").validate({
            rules:{
                old_password:{
                    required:true
                },
                password:{
                    required:true,
                    maxlength:20,
                    minlength:6
                },
                password_confirmation: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('system/user/password_edit')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("修改密码成功!");
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('修改密码失败!');
                    }
                });
            }
        });
    </script>
@endsection